package com.lirh.pojo;

import com.lirh.poi.PreTestReadXlsToNode;


import java.util.*;

public class MultiTree {
    private TreeNode root;
    private List pathList=new ArrayList();
    public static final String SIGN_BEGIN="signal=newCall";
    public    String key=SIGN_BEGIN;


    public int threshold=0;

    //递归+节点不重复
    public String repeatStr;
    public void listPath(TreeNode root,String path){


        if (root.getChilds().isEmpty()){//叶子节点
            path=path+key+"->"+root.getContent();
            pathList.add(path);
            key="";
            return;
        }else{//非叶子节点
            path=path+key+"->"+root.getContent()+"->";
            key="";

            HashMap<String, TreeNode> childs = root.getChilds();
            Iterator<Map.Entry<String, TreeNode>> iterator = childs.entrySet().iterator();

            while (iterator.hasNext()){
                System.out.println("path:"+path);
                System.out.println("pathlist:"+pathList);
                Map.Entry<String, TreeNode> entry = iterator.next();
                key =key+ entry.getKey();
              //  System.out.println("key。。。"+key);
 //               System.out.println("用户回复："+entry.getKey());
                TreeNode childNode = entry.getValue();
   //             System.out.println("childnode.getcontent:"+childNode.getContent());
                if (path.contains(childNode.getContent())){
                    repeatStr=path;
                    repeatStr=repeatStr+key+"->"+childNode.getContent();
                    pathList.add(repeatStr);
//                    path=path+key+"->"+childNode.getContent();
//                    pathList.add(path);
                    key="";
                   // break;
                }else {
                    listPath(childNode, path);
                }


            }


        }
    }

//用例
    public List<String> listAllPathByRecursion(String file,String sheet) throws Exception {
        //清空路径容器
        this.pathList.clear();
        PreTestReadXlsToNode testReadXlsToNode = new PreTestReadXlsToNode();
        testReadXlsToNode.importExcel(file,sheet);
        TreeNode r = testReadXlsToNode.firstNode;
        listPath(r,"");
        return pathList;

    }
    //用例+请求
    public List<String> listAllPathByRecursion2(String file,String sheet) throws Exception {
        this.pathList.clear();
        PreTestReadXlsToNode testReadXlsToNode = new PreTestReadXlsToNode();
        testReadXlsToNode.importExcel(file,sheet);
        TreeNode r = testReadXlsToNode.firstNode;
        listPath(r,"");
        return pathList;


    }
}
